package com.zhkj.txg.module.order.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import com.zhkj.txg.R
import razerdp.basepopup.BasePopupWindow

class OrderReceiveReasonPopupWindow(
    context: Context,
    val onSelected: (content: String) -> Unit
) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.BOTTOM
    }

    private var viewRefundUnlike: View? = null
    private var viewRefundEmpty: View? = null
    private var viewRefundDelay: View? = null
    private var viewRefundFake: View? = null
    private var viewRefundMiss: View? = null

    override fun onCreateContentView(): View = createPopupById(R.layout.popup_refund_reason)
    override fun onCreateShowAnimation(): Animation = getTranslateVerticalAnimation(1f, 0f, 300)
    override fun onCreateDismissAnimation(): Animation = getTranslateVerticalAnimation(0f, 1f, 300)

    override fun onViewCreated(contentView: View?) {
        viewRefundUnlike = contentView?.findViewById(R.id.viewRefundUnlike)
        viewRefundEmpty = contentView?.findViewById(R.id.viewRefundEmpty)
        viewRefundDelay = contentView?.findViewById(R.id.viewRefundDelay)
        viewRefundFake = contentView?.findViewById(R.id.viewRefundFake)
        viewRefundMiss = contentView?.findViewById(R.id.viewRefundMiss)
        contentView?.findViewById<View>(R.id.ivRefundReceiveClose)?.setOnClickListener {
            dismiss()
        }
        viewRefundUnlike?.setOnClickListener {
            notSelectAll()
            it.isSelected = true
            onSelected(context.getString(R.string.refund_reason_unlike))
            dismiss()
        }
        viewRefundEmpty?.setOnClickListener {
            notSelectAll()
            it.isSelected = true
            onSelected(context.getString(R.string.refund_reason_empty))
            dismiss()
        }
        viewRefundDelay?.setOnClickListener {
            notSelectAll()
            it.isSelected = true
            onSelected(context.getString(R.string.refund_reason_delay))
            dismiss()
        }
        viewRefundFake?.setOnClickListener {
            notSelectAll()
            it.isSelected = true
            onSelected(context.getString(R.string.refund_reason_fake))
            dismiss()
        }
        viewRefundMiss?.setOnClickListener {
            notSelectAll()
            it.isSelected = true
            onSelected(context.getString(R.string.refund_reason_miss))
            dismiss()
        }
    }

    private fun notSelectAll() {
        viewRefundUnlike?.isSelected = false
        viewRefundEmpty?.isSelected = false
        viewRefundDelay?.isSelected = false
        viewRefundFake?.isSelected = false
        viewRefundMiss?.isSelected = false
    }
}